package leecode

import "strings"

type MapSum struct {
	newMap map[string]int
}

func Constructor677() MapSum {
	newMap := make(map[string]int)
	return MapSum{newMap: newMap}
}

func (this *MapSum) Insert(key string, val int) {
	this.newMap[key] = val
}

func (this *MapSum) Sum(prefix string) (sum int) {
	for s, v := range this.newMap {
		//前缀
		if strings.HasPrefix(s, prefix) {
			sum += v
		}
	}
	return
}
